# -*- coding: utf-8 -*-

import re
import linecache

pkglistfile = open('pkglist.txt', 'r') 

def findLine(pkg):
  #finds line for given package name
  #TODO: add exception when nothing found
  pkglistfile.seek(0)
  linenumber = 1
  for line in pkglistfile:
      regexp = '^' + pkg
      if re.match(regexp, line):
          return linenumber
      linenumber += 1
  

def readPkgName(line):
  #reads package name (first column) in given line
  #stores all file in memory, find better solution
  line = linecache.getline('pkglist.txt',line)
  splitline =  re.split(' ', line)
  return splitline[0]

def readPkgFile(line):
  #reads package filename (second column) in given line
  line = linecache.getline('pkglist.txt',line)
  splitline =  re.split(' ', line)
  return splitline[1]

def readPkgLocation(line):
  #reads package location in reprository (third column) in given line
  line = linecache.getline('pkglist.txt',line)
  splitline =  re.split(' ', line)
  return splitline[2]